package oop4.graph;

public class Triangle extends Graph {
    double a, b, c;
    double area, round;
    boolean s = true;

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Override
    public double getArea() {
        if (a + b <= c || a + c <= b || b + c <= a) {
            System.out.println("存在两边之和不大于第三边的情况，不构成三角形");
            s = false;
            return 0;
        }
        getRound(); //调用执行该方法，成员变量round才会被赋值，否则round为默认值0.0
        double p = round / 2;   //也可不要上条语句，直接  double p = getRound()/2;
        area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
        return area;
    }

    @Override
    public double getRound() {
        if (s == false) {
            return 0;
        }
        round = (a + b + c);
        return round;
    }
}
